package com.le.tester.tip;

import java.util.concurrent.TimeUnit;

/**
 * createTime：2022/2/10 16:01
 * description：让出cpu时间片
 */
public class YieldDemo3 {
    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = () -> {
            //lamboda中的run方法
            for (int i = 0; i < 100; i++) {
                System.out.println(Thread.currentThread().getName() + "=======" + i);
                if (i % 20 == 0) {
                    Thread.yield();
                }
            }
        };
        new Thread(runnable, "大").start();
        new Thread(runnable, "小").start();
    }
}
